//
// Created by tianq on 25-1-4.
//
#include <iostream>
using namespace std;

int main() {
    // c: item count, s: bag size
    // following c lines, each line si,vi
    // si: size, vi: value
    int c, s;
    cin >> c >> s;

    int *arr = new int[s + 1];
    for (int i = 0; i < s + 1; i++) arr[i] = 0;

    // parse all items
    for (int i = 0; i < c; i++) {
        int si, vi;
        cin >> si >> vi;
        // for each item, check if total value gets higher once it fits
        // for memory saving, we traverse the process instead of making tmp
        for (int ts = s - si; ts >= 0; ts--) {
            if (arr[ts + si] >= arr[ts] + vi) continue;
            arr[ts + si] = arr[ts] + vi;
        }
    }

    cout << arr[s];
    free(arr);
}
